<template>
  <div class="container">
    <el-dialog
      title="题目预览"
      :visible="dialogVisible"
      width="45%"
      @close="closeDialog"
      @open="openDialog"
    >
     <el-row>
        <el-col :span="6">【题型】:{{itemData.questionType}}</el-col>
        <el-col :span="6">【编号】：{{itemData.id}}</el-col>
        <el-col :span="6">【难度】：{{itemData.difficulty}}</el-col>
        <el-col :span="6">【标签】：{{itemData.tags}}</el-col>
        <el-col :span="6">【学科】：{{itemData.subjectName}}</el-col>
        <el-col :span="6">【目录】：{{itemData.directoryName}}</el-col>
        <el-col :span="6">【方向】：{{itemData.direction}}</el-col>
      </el-row>
      <hr>
      【题干】：
      <div style="color: blue;">
        <p v-html="itemData.question"></p>
      </div>
      <div>
        <div style="padding-bottom: 5px;"> {{question[itemData.questionType]}}选项：（以下选中的选项为正确答案）</div>
        <div class="radio" v-for="item in itemData.options" :key="item.code">
          <el-radio
            @click.native="stopPrevent"
            v-if="question[itemData.questionType] === '单选'"
            v-model="radio"
            :label="item.isRight"
            >
            {{item.title}}
          </el-radio>
          <el-checkbox
          @click.native="stopPrevent"
            v-model="checkList"
            v-else-if="question[itemData.questionType] === '多选'"
            :checked="item.isRight === 1"
            :label="item.code"
            >
            {{item.title}}
          </el-checkbox>
          <div v-else></div>
        </div>
      </div>
       <hr>
      【参考答案】：
      <el-button @click="videoShow(itemData.videoURL)" type="danger" size="small">视频答案预览</el-button>
      <div>
        <video
          :src="itemData.videoURL"
          style="width:300px"
          v-if="isShow"
          controls="controls" muted>
        </video>
      </div>

      <hr>
      【答案解析】：
      <div style="display: inline-block">
        <p v-html="itemData.answer">{{itemData.answer}}</p>
      </div>
      <hr>
      【题目备注】：{{itemData.remarks}}
      <span slot="footer" class="dialog-footer">
        <el-button size="middle" type="primary" @click="$emit('close-dialog')">关 闭</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { detail } from '@/api/hmmm/questions'
export default {
  data () {
    return {
      // 存储父组件传递的数据
      itemData: '',
      radio: 1,
      // 多选框列表
      checkList: [],
      // 控制视频的显示和隐藏
      isShow: false
    }
  },
  props: {
    dialogVisible: {
      type: Boolean,
      required: true
    },
    quesID: {
      type: Number,
      required: true
    },
    question: {
      type: Object,
      required: true
    },
    diff: {
      type: Object,
      required: true
    }
  },
  methods: {
    async openDialog () {
      const res = await detail({
        id: this.quesID
      })
      console.log(res)
      this.itemData = res.data
    },
    closeDialog () {
      this.$emit('close-dialog')
    },
    stopPrevent (e) {
      e.preventDefault()
    },
    videoShow (url) {
      if (url !== '') this.isShow = !this.isShow
    }
  }
}

</script>

<style>
.container .el-col {
    padding: 10px 0;
}
.container .radio {
  padding: 8px 0px;
}
.container >>> .el-dialog__footer {
    text-align: right;
    padding: 10px 20px 20px;
    text-align: right;
    box-sizing: border-box;
}
</style>
